package com.dj.dormitory.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dj.dormitory.commonutils.Result;
import com.dj.dormitory.entity.Dormitory;
import com.dj.dormitory.entity.Storey;
import com.dj.dormitory.service.DormitoryService;
import org.apache.catalina.Store;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author DJ同学
 * @since 2021-01-24
 */
@RestController
@RequestMapping("/dormitory")
public class DormitoryController {
    @Autowired
    private DormitoryService dormitoryService;
    //根据storeyId获得宿舍
    @PostMapping("/getList")
    public Result getList(@RequestBody Dormitory dormitory){
        QueryWrapper<Dormitory> wrapper = new QueryWrapper<>();
        wrapper.eq("storey_id",dormitory.getStoreyId());
        List<Dormitory> list = dormitoryService.list(wrapper);
        return Result.ok().data("dormitorys",list);
    }
    //获得一栋楼的宿舍
    //使用对象接收就不会出现 {"buildingId":"2"} 字符串
    @PostMapping("/list")
    public Result getListByBuildingId(@RequestBody Dormitory dormitory){
        QueryWrapper<Dormitory> wrapper = new QueryWrapper<>();
        wrapper.eq("building_id",dormitory.getBuildingId());
        List<Dormitory> list = dormitoryService.list(wrapper);
        return Result.ok().data("list",list);
    }
}

